package chat.server;

import chat.logic.CheckOl;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Timer;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @time Oct 28, 2009, 16:50:54 PM
 * @author fdcube
 * @version FreeChat-Server v1.1.2
 */
public class ChatServer {

    ServerSocket Server;
    private int ServerPort = 80;
    private int BackLog = 0;
    private InetAddress BindAddr = null;

    public static void main(String args[]) {
        new ChatServer(80, 0, null).RunServer();
    }

    public ChatServer(int ServerPort, int BackLog, InetAddress BindAddr) {
        this.ServerPort = ServerPort;
        this.BackLog = BackLog;
        this.BindAddr = BindAddr;
    }

    public void RunServer() {
        try {
            new Timer().schedule(new CheckOl(), 20173, 30029);
            Server = new ServerSocket(ServerPort, BackLog, BindAddr);
            Logger.getLogger(ChatServer.class.getName()).log(Level.INFO, "Server Started On Port:" + ServerPort);
            int i = 1;
            for (;;) {
                Socket client = Server.accept();
                new Connection(client, i).start();
                i++;
            }
        } catch (IOException ex) {
            Logger.getLogger(ChatServer.class.getName()).log(Level.SEVERE, "Error", ex);
        }
    }
}
